package com.lwlean.audit.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by lean on 16-11-6.
 */
public class SystemInterceptor extends HandlerInterceptorAdapter{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        if(session.getAttribute("currentUser")==null){
            //销毁当前session
            session.invalidate();
            response.sendRedirect("/loginPage");
            return false;
        }
        return true;
    }
}
